/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.branches;
import java.util.ArrayList;
import javax.swing.JTable;

/**
 *
 * @author lyan
 */
public class branchesControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    branches bra = new branches();

    public void getlistbranches(JTable table) {

        String sql = "select * from Branches";
        String[] header = {"BranchesID", "BranchName", "Address", "Email"};
        Helper.loadDataTable(sql, table, header);
    }

    public void insertbranches(branches bra) {
        Object[] values = {bra.getBranchesName(), bra.getAddress(), bra.getEmail()};
        JDBCHelper.excuteInsertPlaceHolder("Branches", 3, values);
        Helper.successMessage("Insert  successfull", "wanning");
    }

    public void updatebranches(branches bra) {
        String[] objColumn = {"BranchName", "Address"," Email"};
        String[] objValues = {bra.getBranchesName(), bra.getAddress(), bra.getEmail()};

        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("Branches", listColumn, listValue, "BranchesID", String.valueOf(bra.getBranchesID()));
        Helper.successMessage("Update Sucessful", "wanning");
    }

    private int checkDeltebranches(String values) {
        return JDBCHelper.excuteQueryReturnInt("BranchesID", "Customers ", values);
    }

    public void Deletebranches(branches bra) {
        if (checkDeltebranches(String.valueOf(bra.getBranchesID())) > 0) {
            Helper.inforMessage("Can not detlete this branches", "Wanning");
        } else {
            JDBCHelper.excuteDelete("Branches", "BranchesID", String.valueOf(bra.getBranchesID()));
            Helper.successMessage("Delete successfull", "wanning");
        }

    }
}
